

import java.awt.*;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Stefano
 */
public class ControlloAccessoRegistra extends javax.swing.JDialog {
    private final Frame parent2;
 
   
    private boolean ans=false;

    /**
     * Creates new form AnagraficaInserisci l'int sta per
     * 1=fornitore,2=cliente,3=agente
     */
    public ControlloAccessoRegistra(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        parent2=parent;
        
        if(!this.controlloPresenzaAdmin())
        {Errore er=new Errore(parent2,true);
        er.settitolo("Admin non presente");
        er.setmessaggio("Definire le credenziali di Admin");
        er.setVisible(true);
        NuovoUtente nu = new NuovoUtente(parent2,true);
        nu.Carica(null, null, 0);
        nu.setVisible(true);
         initComponents();
          Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(new Point(
				(dimension.width - this.getSize().width) / 2,
				(dimension.height - this.getSize().height) / 2));
        }
        
       
        
        
        
       
       
       
               
    }

    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pannelloInfo = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton5 = new javax.swing.JToggleButton();
        jPanel3 = new javax.swing.JPanel();
        titolo = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jPasswordField1 = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        pannelloInfo.setBackground(new java.awt.Color(255, 255, 255));
        pannelloInfo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel21.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel21.setText("User");

        jLabel23.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel23.setText("Password");

        jToggleButton3.setToolTipText("Cerca Modello Base");
        jToggleButton3.setBorder(null);
        jToggleButton3.setContentAreaFilled(false);
        jToggleButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton3MouseClicked(evt);
            }
        });

        jToggleButton5.setToolTipText("Cerca Linea");
        jToggleButton5.setBorder(null);
        jToggleButton5.setContentAreaFilled(false);
        jToggleButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton5MouseClicked(evt);
            }
        });

        jPanel3.setBackground(new java.awt.Color(0, 51, 204));

        titolo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        titolo.setForeground(new java.awt.Color(255, 255, 255));
        titolo.setText("Inserisci credenziali admin");

        jPanel7.setBackground(new java.awt.Color(204, 204, 204));
        jPanel7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 21, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titolo)
                .addContainerGap())
            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(titolo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jButton1.setText("Accedi");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout pannelloInfoLayout = new javax.swing.GroupLayout(pannelloInfo);
        pannelloInfo.setLayout(pannelloInfoLayout);
        pannelloInfoLayout.setHorizontalGroup(
            pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel21)
                    .addComponent(jLabel23))
                .addGap(61, 61, 61)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addGroup(pannelloInfoLayout.createSequentialGroup()
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nome, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
                            .addComponent(jPasswordField1))
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pannelloInfoLayout.createSequentialGroup()
                                .addGap(69, 69, 69)
                                .addComponent(jToggleButton5))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pannelloInfoLayout.createSequentialGroup()
                                .addGap(79, 79, 79)
                                .addComponent(jToggleButton3)))))
                .addContainerGap())
        );
        pannelloInfoLayout.setVerticalGroup(
            pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pannelloInfoLayout.createSequentialGroup()
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel21))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)
                        .addGap(137, 137, 137))
                    .addComponent(jToggleButton5))
                .addGap(9, 9, 9)
                .addComponent(jToggleButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(pannelloInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pannelloInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    //modifica il titolo    
    public boolean risposta(){return ans;}
    
    
    private void jToggleButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton3MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton3MouseClicked

    private void jToggleButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton5MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton5MouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
     if(this.controlloAccediRegistra(this.nome.getText(),this.jPasswordField1.getText())){
            try {
                this.setVisible(false);
                ApriUtente nu=new ApriUtente(parent2,true); 
                nu.setVisible(true);
            } catch (SQLException ex) {
                Logger.getLogger(ControlloAccessoRegistra.class.getName()).log(Level.SEVERE, null, ex);
            }
     
     }
     else {Errore er= new Errore(parent2,true);er.settitolo("Accesso Negato");er.setmessaggio("Ricontrolla i campi");
     er.setVisible(true);}// TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseClicked

   
            
            
    /**
     * @param args the command line arguments
     */ 
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton5;
    private javax.swing.JTextField nome;
    private javax.swing.JPanel pannelloInfo;
    private javax.swing.JLabel titolo;
    // End of variables declaration//GEN-END:variables

    private static Boolean controlloAccediRegistra(java.lang.String utente, java.lang.String pass) {
        gruppo12.LoginService_Service service = new gruppo12.LoginService_Service();
        gruppo12.LoginService port = service.getLoginServicePort();
        return port.controlloAccediRegistra(utente, pass);
    }

    private static Boolean controlloPresenzaAdmin() {
        gruppo12.LoginService_Service service = new gruppo12.LoginService_Service();
        gruppo12.LoginService port = service.getLoginServicePort();
        return port.controlloPresenzaAdmin();
    }

   
    

    

 

    
}
